"use strict";
cc._RF.push(module, '15af7Gon9tIl6PPTsuDBnSe', 'Box');
// script/Box.js

"use strict";

/**
 * 直行道具的阻挡栅栏
 */
cc.Class({
    extends: cc.Component,

    properties: {},

    // onLoad () {},

    // start() {},

    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function onBeginContact(contact, selfCollider, otherCollider) {
        //如果是火箭状态的话让栅栏隐藏，正常人物状态不做操作
        if (otherCollider.node.prop === "Rocket" || otherCollider.node.prop === "Moto") {
            selfCollider.node.active = false;
        }
        //保存火箭与栅栏碰撞时的线速度
        this.linearVelocityX = otherCollider.node.getComponent(cc.RigidBody)._b2Body.m_linearVelocity.x;
        this.linearVelocityY = otherCollider.node.getComponent(cc.RigidBody)._b2Body.m_linearVelocity.y;
    },

    // 每次处理完碰撞体接触逻辑时被调用
    onPostSolve: function onPostSolve(contact, selfCollider, otherCollider) {
        //碰撞结束时还原人物与栅栏碰撞时的线速度
        if (otherCollider.node.prop === "Rocket" || otherCollider.node.prop === "Moto") {
            otherCollider.node.getComponent(cc.RigidBody)._b2Body.m_linearVelocity.x = this.linearVelocityX;
            otherCollider.node.getComponent(cc.RigidBody)._b2Body.m_linearVelocity.y = this.linearVelocityY;
        }
    }
});

cc._RF.pop();